package net.luoran.dvm.controller;

import net.luoran.dvm.common.annotation.PassToken;
import net.luoran.dvm.common.base.Result;
import net.luoran.dvm.common.base.ResultEnum;
import net.luoran.dvm.common.util.JwtUtil;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;


/**
 * @author： M1nG
 * @since： 2020-10-17 17:35:51
 * @description： 简历列表展示控制器
 * @version： 1.0
 */
@Controller
@RequestMapping(value = "/")
@PassToken
public class DvmController {

    @Value("${server.servlet.context-path}")
    public String contextPath;

    @GetMapping
    public String dvmMain() {
        return "redirect:/index";
    }

    @GetMapping("/index")
    public String index(Model model) {
        model.addAttribute("contextPath", contextPath);
        return "index";
    }

    @RequestMapping("/auth")
    @ResponseBody
    public Result index(@RequestParam("token") String token) {
        boolean verify = JwtUtil.verify(token);
        if (verify) {
            return Result.build(ResultEnum.SUCCESS);
        } else {
            return Result.build(ResultEnum.NO_LOGIN);
        }
    }


}
